package Others;

public class _419_BattleshipsinaBoard {
    public int countBattleships(char[][] board) {
        int row = board.length;
        int column = board[0].length;
        int ans = 0;
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < column; j++) {
                //every board's left and top slot can't be 'X'
                if (!((i - 1 >= 0 && board[i - 1][j] == 'X') || (j - 1 >= 0 && board[i][j - 1] == 'X'))) {
                    if (board[i][j] == 'X') {
                        ans++;
                    }
                }
            }
        }
        return ans;
    }
}
